<template>
  <div>
    <h1>
      Salegoods-ElasticSearch
    </h1>
    <!--搜索框-->
    <el-form :inline="true" ref="form" :model="queryLike" label-width="80px">
      <el-form-item label="通用搜索">
        <el-input v-model="queryLike.name" placeholder="输入要查找的字段"></el-input>
      </el-form-item>
      <el-form-item label="状态">
        <el-radio-group v-model="queryLike.state">
          <el-radio :label="2">待审核</el-radio>
          <el-radio :label="1">正常</el-radio>
          <el-radio :label="0">封禁</el-radio>
          <el-radio :label="''">所有</el-radio>
        </el-radio-group>
      </el-form-item>
      <br>
      <el-form-item label="创建时间">
        <el-col :span="11">
          <el-date-picker type="date" placeholder="选择开始日期" v-model="queryLike.startTime1"
                          style="width: 100%;"></el-date-picker>
        </el-col>
        <el-col class="line" :span="2" style="text-align:center">-</el-col>
        <el-col :span="11">
          <el-time-picker placeholder="选择开始时间" v-model="queryLike.startTime2" style="width: 100%;"></el-time-picker>
        </el-col>
      </el-form-item>
      <el-form-item>
        <el-col :span="11">
          <el-date-picker type="date" placeholder="选择结束日期" v-model="queryLike.endTime1"
                          style="width: 100%;"></el-date-picker>
        </el-col>
        <el-col class="line" :span="2" style="text-align:center">-</el-col>
        <el-col :span="11">
          <el-time-picker placeholder="选择结束时间" v-model="queryLike.endTime2" style="width: 100%;"></el-time-picker>
        </el-col>
      </el-form-item>
      <br>
      <el-form-item label="排序类型">
        <el-radio-group v-model="queryLike.sortType">
          <el-radio :label="1">降序</el-radio>
          <el-radio :label="0">升序</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="排序依据">
        <el-radio-group v-model="queryLike.sortBy">
          <el-radio :label="10">创建时间</el-radio>
          <el-radio :label="4">浏览量</el-radio>
          <el-radio :label="5">销量</el-radio>
        </el-radio-group>
      </el-form-item>
      <br>
      <el-form-item label="页数">
        <el-input v-model="queryLike.page" width="20" placeholder="输入当前页"></el-input>
      </el-form-item>
      <el-form-item label="页内条数">
        <el-input v-model="queryLike.pageSize" width="20" placeholder="输入单页总条数"></el-input>
      </el-form-item>
      <el-form-item>
        <!--查询按钮-->
        <el-button type="primary" @click="search(queryLike)" icon="el-icon-search" value="查询"></el-button>
        <!--添加按钮-->
        <el-button style="float:right" type="success" icon="el-icon-circle-plus-outline" @click="insert()"
                   value="添加"></el-button>
      </el-form-item>
    </el-form>
    <!--添加填出的对话框(和修改是同一个)-->
    <el-dialog title="商品" :visible.sync="dialogFormVisible">
      <el-form :model="pojo">
        <el-form-item label="商品名称" :label-width="formLabelWidth">
          <el-input v-model="pojo.name" autocomplete="on"></el-input>
        </el-form-item>
        <el-form-item label="商品显示价格" :label-width="formLabelWidth">
          <el-input v-model="pojo.price" autocomplete="on"></el-input>
        </el-form-item>
        <el-form-item label="所属商家id" :label-width="formLabelWidth">
          <el-input v-model="pojo.merchant.mid" autocomplete="on" disabled></el-input>
        </el-form-item>
        <el-form-item label="标签id" :label-width="formLabelWidth">
          <!--标签选择的单选框-->
          <el-radio-group v-model="pojo.card.caid" v-for="item in cardList">
            <el-radio :label=item.caid>{{item.name}}</el-radio>
          </el-radio-group>
          <!--<el-input v-model="pojo.card.caid" autocomplete="on"></el-input>-->
        </el-form-item>
        <el-form-item label="图片id" :label-width="formLabelWidth">
          <el-input v-model="pojo.picture.picid" autocomplete="on" disabled></el-input>
        </el-form-item>
        <el-form-item label="商品介绍id" :label-width="formLabelWidth">
          <el-input v-model="pojo.describe.iid" autocomplete="on" disabled></el-input>
        </el-form-item>
        <el-form-item label="参与活动id" :label-width="formLabelWidth">
          <!--活动选择的单选框-->
          <el-radio-group v-model="pojo.activity.aid" v-for="item in activeList">
            <el-radio :label=item.aid>{{item.name}}</el-radio>
          </el-radio-group>
          <!--<el-input v-model="pojo.activity.aid" autocomplete="on"></el-input>-->
        </el-form-item>
        <el-form-item label="库存总量" :label-width="formLabelWidth">
          <el-input v-model="pojo.number" autocomplete="on"></el-input>
        </el-form-item>
        <el-form-item label="浏览量" :label-width="formLabelWidth">
          <el-input v-model="pojo.view" autocomplete="on"></el-input>
        </el-form-item>
        <el-form-item label="销售量" :label-width="formLabelWidth">
          <el-input v-model="pojo.sale" autocomplete="on"></el-input>
        </el-form-item>
        <el-divider>套餐列表</el-divider>
        <!--添加按钮-->
        <el-button style="float:left" type="success" icon="el-icon-circle-plus" @click="saveSalegoods(pojo.gid)"
                   value="添加"></el-button>
        <br><br><br>
        <!--套餐-->
        <div v-for="item in pojo.list">
          <el-form :model="item">
            <el-form-item label="取消" :label-width="formLabelWidth2">
              <!--取消按钮-->
              <el-button style="float:right" type="error" icon="el-icon-remove" @click="deleteSalegoods(item)"
                         value="减少"></el-button>
            </el-form-item>
            <el-form-item label="价格" :label-width="formLabelWidth2">
              <el-input v-model="item.price" autocomplete="on"></el-input>
            </el-form-item>
            <el-form-item label="数量" :label-width="formLabelWidth2">
              <el-input v-model="item.number" autocomplete="on"></el-input>
            </el-form-item>
            <el-form-item label="单位" :label-width="formLabelWidth2">
              <el-input v-model="item.unit" autocomplete="on"></el-input>
            </el-form-item>
          </el-form>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="save(pojo)">确 定</el-button>
      </div>
    </el-dialog>
    <!--内容对话框-->
    <el-dialog
      title="全文"
      :visible.sync="centerDialogVisible"
      width="30%"
      center>
      <p v-html="this.content"></p>
    </el-dialog>
    <!--换头像的对话框-->
    <el-dialog title="换图片" :visible.sync="Avatar">
      <center>
        <el-upload
          class="upload-demo"
          drag
          :action='baseURL + "client/"+"Picture"+"/upload?" + "OperatorId=" + pojo.mid'
          :on-success="saveAvatar"
          multiple>
          <i class="el-icon-upload"></i>
          <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
          <div class="el-upload__tip" slot="tip">只能上传jpg/png文件，且不超过10MB</div>
        </el-upload>
      </center>
    </el-dialog>
    <!--修改备注的对话框-->
    <el-dialog title="换介绍" :visible.sync="Introduce">
      <el-form>
        <el-card style="height: 610px;">
          <center>
            <!--富文本-->
            <quill-editor v-model="pojo.describe.content" ref="myQuillEditor" style="height: 500px;"
                          :options="editorOption"
                          @blur="" @focus=""
                          @change=""
            >
              <!-- 自定义toolar -->
              <div id="toolbar" slot="toolbar">
                <!-- Add a bold button -->
                <button class="ql-bold" title="加粗">Bold</button>
                <button class="ql-italic" title="斜体">Italic</button>
                <button class="ql-underline" title="下划线">underline</button>
                <button class="ql-strike" title="删除线">strike</button>
                <button class="ql-blockquote" title="引用"></button>
                <button class="ql-code-block" title="代码"></button>
                <button class="ql-header" value="1" title="标题1"></button>
                <button class="ql-header" value="2" title="标题2"></button>
                <!--Add list -->
                <button class="ql-list" value="ordered" title="有序列表"></button>
                <button class="ql-list" value="bullet" title="无序列表"></button>
                <!-- Add font size dropdown -->
                <select class="ql-header" title="段落格式">
                  <option selected>段落</option>
                  <option value="1">标题1</option>
                  <option value="2">标题2</option>
                  <option value="3">标题3</option>
                  <option value="4">标题4</option>
                  <option value="5">标题5</option>
                  <option value="6">标题6</option>
                </select>
                <select class="ql-size" title="字体大小">
                  <option value="10px">10px</option>
                  <option value="12px">12px</option>
                  <option value="14px">14px</option>
                  <option value="16px" selected>16px</option>
                  <option value="18px">18px</option>
                  <option value="20px">20px</option>
                  <option value="20px">22px</option>
                  <option value="20px">24px</option>
                  <option value="20px">26px</option>
                  <option value="20px">28px</option>
                  <option value="20px">30px</option>
                </select>
                <select class="ql-font" title="字体">
                  <option value="SimSun">宋体</option>
                  <option value="SimHei">黑体</option>
                  <option value="Microsoft-YaHei">微软雅黑</option>
                  <option value="KaiTi">楷体</option>
                  <option value="FangSong">仿宋</option>
                  <option value="Arial">Arial</option>
                </select>
                <!-- Add subscript and superscript buttons -->
                <select class="ql-color" value="color" title="字体颜色"></select>
                <select class="ql-background" value="background" title="背景颜色"></select>
                <select class="ql-align" value="align" title="对齐"></select>
                <button class="ql-clean" title="还原"></button>
                <!-- You can also add your own -->
                <button class="ql-link" title="链接"></button>
                <button class="ql-image" title="图片"></button>
                <button class="ql-video" title="视频"></button>
              </div>
            </quill-editor>
          </center>
        </el-card>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="Introduce = false">取 消</el-button>
        <el-button type="primary" @click="saveIntroduce()">确 定</el-button>
      </div>
    </el-dialog>
    <!--套餐对话框-->
    <el-dialog
      title="套餐"
      :visible.sync="packageDialogVisible"
      width="75%"
      center>
      <el-table :data="packageList.list" style="width: 100%" max-height="500px">
        <el-table-column fixed property="sgid" label="主键"></el-table-column>
        <el-table-column property="gid" label="商品id"></el-table-column>
        <el-table-column property="price" label="价格"></el-table-column>
        <el-table-column property="number" label="数量"></el-table-column>
        <el-table-column property="unit" label="单位"></el-table-column>
        <el-table-column property="creattime" label="创建时间" width="150"></el-table-column>
        <el-table-column property="state" label="状态码"></el-table-column>
        <el-table-column
          fixed="right"
          label="操作"
          width="200">
          <template slot-scope="scope">
            <el-button v-if="scope.row.state===1" type="info" icon="el-icon-video-pause" value="封禁"
                       @click="enable2(scope.row,packageList,1,scope.row.sgid,0)" circle></el-button>
            <el-button v-if="scope.row.state!==1" type="info" icon="el-icon-video-play" value="启用"
                       @click="enable2(scope.row,packageList,1,scope.row.sgid,1)" circle></el-button>
            <el-button v-if="power===3" type="danger" icon="el-icon-delete" value="删除"
                       @click="phydele2(scope.row,packageList,1,scope.row.sgid)"
                       circle></el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
    <!--列表-->
    <el-table :data="user" style="width: 100%" max-height="600">
      <el-table-column fixed property="gid" label="主键"></el-table-column>
      <el-table-column property="name" label="商品名称"></el-table-column>
      <el-table-column property="price" label="商品显示价格"></el-table-column>
      <el-table-column property="merchant.name" label="商家"></el-table-column>
      <el-table-column property="card.name" label="标签"></el-table-column>
      <el-table-column property="state" label="状态码"></el-table-column>
      <el-table-column property="creattime" label="创建时间" width="150"></el-table-column>
      <el-table-column property="picture.url" label="商品图片">
        <template slot-scope="scope">
          <el-image
            style="width: 100px; height: 100px"
            :src="baseURL+'data/picture/'+scope.row.picture.url"
            :preview-src-list="[baseURL+'data/picture/'+scope.row.picture.url]"
            fit='cover'
          >
          </el-image>
          <el-button type="text" @click="changeAvatar(scope.row)">修改图片</el-button>
        </template>
      </el-table-column>
      <el-table-column property="describe.content" label="具体介绍">
        <template slot-scope="scope">
          <p v-html="scope.row.describe.content" class="product-buyer-name"></p>
          <el-button type="text" @click="Content(scope.row.describe.content)">查看完整内容</el-button>
          <el-button type="text" @click="changeIntroduce(scope.row)">修改介绍</el-button>
        </template>
      </el-table-column>
      <el-table-column property="number" label="库存数量"></el-table-column>
      <el-table-column property="activity.name" label="参与活动名称"></el-table-column>
      <el-table-column property="view" label="浏览量"></el-table-column>
      <el-table-column property="sale" label="销售量"></el-table-column>
      <el-table-column
        fixed="left"
        label="套餐">
        <template slot-scope="scope">
          <el-button type="text" @click="packageOn(scope.row)">点击查看套餐</el-button>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        label="操作"
        width="200">
        <template slot-scope="scope">
          <el-button type="primary" icon="el-icon-setting" value="修改" @click="change(scope.row)" circle></el-button>
          <el-button v-if="scope.row.state===1" type="info" icon="el-icon-video-pause" value="封禁"
                     @click="enable(scope.row,0,scope.row.gid,0)" circle></el-button>
          <el-button v-if="scope.row.state!==1" type="info" icon="el-icon-video-play" value="启用"
                     @click="enable(scope.row,0,scope.row.gid,1)" circle></el-button>
          <el-button v-if="power===3" type="danger" icon="el-icon-delete" value="删除"
                     @click="phydele(scope.row,0,scope.row.gid)"
                     circle></el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import {mapGetters} from 'vuex'
import {
  Quill,
  quillEditor
} from 'vue-quill-editor'
import '../../../src/assets/css/font.css'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'

let Size = Quill.import('attributors/style/size')
Size.whitelist = ['10px', '12px', '14px', '16px', '18px', '20px', '22px', '24px', '26px', '28px', '30px']
Quill.register(Size, true)

// 自定义字体类型
let fonts = ['SimSun', 'SimHei', 'Microsoft-YaHei', 'KaiTi', 'FangSong', 'Arial', 'Times-New-Roman', 'sans-serif',
  '宋体', '黑体'
]
let Font = Quill.import('formats/font')
Font.whitelist = fonts
Quill.register(Font, true)
export default {
  name: "Salegoods",
  props: {},
  components: {quillEditor},
  data() {
    return {
      /**
       * @头像
       * */
      Avatar: false,
      /**
       * @备注
       * */
      Introduce: false,
      /**
       * @富文本默认内容
       * */
      editorOption: {
        placeholder: "请输入",
        theme: "snow", // or 'bubble'
        modules: {
          toolbar: {
            container: '#toolbar'
          }
        }
      },
      /**
       * @标签列表
       * */
      cardList:this.$store.state.List.Card,
      /**
       * @活动列表
       * */
      activeList:this.$store.state.List.Activity,
      /**
       * @套餐
       * */
      packageList: "",
      /**
       * @套餐展示
       * */
      packageDialogVisible: false,
      /**
       * @介绍内文
       * */
      content: "",
      /**
       * @展示内容
       * */
      centerDialogVisible: false,
      /***
       * @修改和添加数据类型
       * */
      pojo: this.$store.state.Pojo.GoodsVo,
      /**
       * @弹出的对话框,用于修改和添加数据
       * */
      dialogFormVisible: false,
      /**
       * @对话框内条目的统一长度
       * */
      formLabelWidth: '120px',
      /**
       * @子对话框内条目统一长度
       * */
      formLabelWidth2: '100px',
      /**
       * @表单数据
       * */
      user: this.$store.state.List.GoodsVo,
      /**
       * @权限,页面显示不同权限的操作
       * */
      power: this.$store.state.operator.power,
      /**
       * @查询条件
       * */
      queryLike: {
        OperatorId: "",
        startTime1: "2000-01-01 00:00:00.000+0000",
        startTime2: "2000-01-01 00:00:00.000+0000",
        endTime1: "2099-01-01 00:00:00.000+0000",
        endTime2: "2099-01-01 00:00:00.000+0000",
        name: "",
        price:"",
        page: 1,
        pageSize: 10,
        sortBy: 10,
        sortType: 1,
        state: "",
        merchant: {
          "mid": 0,
          "name": "",
          "password": "",
          "telephone": 0,
          "pic": {
            "picid": "",
            "url": "",
            "creattime": "2021-12-11 14:56:52",
            "state": 0
          },
          "describe": {
            "iid": 0,
            "content": "",
            "creattime": "2021-12-11 14:56:52",
            "updatetime": "2021-12-11 14:56:52",
            "state": 0
          },
          "creattime": "2021-12-11 14:56:52",
          "state": 0
        },
        card: {
          "caid": 0,
          "name": "",
          "creattime": "2021-12-11 14:56:52",
          "state": 0
        },
        picture: {
          "picid": "",
          "url": "",
          "creattime": "2021-12-11 14:56:52",
          "state": 0
        },
        describe: {
          "iid": 0,
          "content": "",
          "creattime": "2021-12-11 14:56:52",
          "updatetime": "2021-12-11 14:56:52",
          "state": 0
        },
        number: 0,
        activity: {
          "aid": 0,
          "type": 0,
          "name": "",
          "rule": {
            "rid": 0,
            "rule": "",
            "creattime": "2021-12-11 14:56:52",
            "state": 0
          },
          "creattime": "2021-12-11 14:56:52",
          "failtime": "2021-12-11 14:56:52",
          "state": 0
        },
        view: 0,
        sale: 0,
        list: [
          {
            "sgid": 0,
            "gid": 0,
            "price": 0.00,
            "number": 0,
            "unit": "",
            "creattime": "2021-12-11 14:56:52",
            "state": 0
          }
        ]
      },
      /**
       * @后端controller名字
       * */
      controller: 'GoodsVo',
    };
  },
  computed: {
    baseURL() {
      return this.$store.state.baseURL;
    }
  },
  /**
   * @加载数据
   */
  created() {
    this.LoadMsg();
    this.LoadCard();
    this.LoadActive();
  },
  /**
   * @static方法
   * */
  mounted() {
    (() => {
      /*console.log(this.$store.state.operator)
      this.power=this.$store.state.operator["power"];
      console.log(this.power);
      console.log(typeof (this.power))*/
    })();
  },
  methods: {
    /**
     * @换图片
     * */
    changeAvatar(val){
      this.pojo = this.$helper.clone(val);
      this.Avatar=true;
    },
    /**
     * 换介绍
     * */
    changeIntroduce(val){
      this.pojo = this.$helper.clone(val);
      this.Introduce=true;
    },
    /**
     * @保存介绍
     * */
    saveIntroduce() {
      let _this = this;
      this.axios.post(this.$store.state.baseURL + 'client/' + 'Introduce' + '/save?' + 'OperatorId=' + this.$store.state.operator.mid,
        {
          iid: "",
          creattime: "",
          updatetime: "",
          content: _this.pojo.describe.content,
          state: 1,
        })
        .then(res => {
          _this.pojo.describe.iid = res.data;
          //console.log(_this.pojo.describe.lid);
          _this.save(_this.pojo);
          this.Introduce=false;
        })
    },
    /**
     * @保存头像
     * */
    saveAvatar(response) {
      //console.log(response)
      this.pojo.picture = response;
      this.save(this.pojo);
      this.Avatar=false;
    },
    /**
     * @判断为空
     * */
    isNull(val){
      if(val===''||val===null||val===undefined){
        return true;
      }
      return false;
    },
    /**
     * @加载标签列表
     * */
    LoadCard(page,pageSize){
      let _this = this;
      if(this.isNull(page)){
        page=1;
      }
      if(this.isNull(pageSize)){
        pageSize=10;
      }
      this.axios.get(this.$store.state.baseURL + 'client/'+'Card'+'/queryLike?' + 'OperatorId=' + this.$store.state.operator.mid + '&state=' + 1
      +'&page='+page+'&pageSize='+pageSize)
        .then(res => {
          for (let i = 0; i < res.data.length; ++i) {
            res.data[i].creattime = _this.$helper.renderTime(res.data[i].creattime);
          }
          _this.cardList = res.data;
          //console.log(res.data);
        })
    },
    /**
     * @加载活动列表
     * */
    LoadActive(page,pageSize){
      let _this = this;
      if(this.isNull(page)){
        page=1;
      }
      if(this.isNull(pageSize)){
        pageSize=10;
      }
      this.axios.get(this.$store.state.baseURL + 'client/'+'Activity'+'/queryLike?' + 'OperatorId=' + this.$store.state.operator.mid + '&state=' + 1
        +'&page='+page+'&pageSize='+pageSize)
        .then(res => {
          for (let i = 0; i < res.data.length; ++i) {
            res.data[i].creattime = _this.$helper.renderTime(res.data[i].creattime);
            res.data[i].failtime = _this.$helper.renderTime(res.data[i].failtime);
          }
          _this.activeList = res.data;
          //console.log(res.data);
        })
    },
    /**
     * @减少指定序列套餐
     * */
    deleteSalegoods2(val,list) {
      for (let i = 0; i < list.length; i++) {
        if (list[i] === val) {
          list.splice(i, 1);
          break;
        }
      }
    },
    /**
     * @减少套餐
     * */
    deleteSalegoods(val) {
      for (let i = 0; i < this.pojo.list.length; i++) {
        if (this.pojo.list[i] === val) {
          this.pojo.list.splice(i, 1);
          break;
        }
      }
    },
    /**
     * @增加套餐
     * */
    saveSalegoods(gid) {
      //console.log(gid)
      if (gid === "" || gid === null || gid === undefined) {
        gid = "";
      }
      let val = this.$helper.clone(this.$store.state.Pojo.Salegoods);
      val.sgid = "";
      val.gid = gid;
      val.state = 1;
      val.unit = "";
      val.price = "";
      val.number = "";
      val.creattime = "";
      this.pojo.list.push(val);
    },
    /**
     * @查询封装函数
     * */
    queryNoNameHaveState(val) {
      let _this = this;
      this.axios.post(this.$store.state.baseURL + 'client/' + this.controller + '/query?'
        + 'OperatorId=' + this.$store.state.operator.mid,
        {
          "merchant.mid":this.$store.state.operator.mid,
          "page": val.page,
          "pageSize": val.pageSize,
          "sortType": val.sortType,
          "sortBy": val.sortBy,
          "state": val.state,
          "startTime": (this.$helper.renderTime(val.startTime1).split(' ')[0] + ' ' + this.$helper.renderTime(val.startTime2).split(' ')[1]),
          "endTime": (this.$helper.renderTime(val.endTime1).split(' ')[0] + ' ' + this.$helper.renderTime(val.endTime2).split(' ')[1])
        })
        .then(res => {
          for (let i = 0; i < res.data.length; ++i) {
            this.dataPreprocessing(res.data[i]);
          }
          _this.$store.state.List.GoodsVo = res.data;
          _this.LoadInfo(res.data);
          //console.log(_this.user);
        })
    },
    /**
     * @查询封装函数
     * */
    queryNoNameNoState(val) {
      let _this = this;
      this.axios.post(this.$store.state.baseURL + 'client/' + this.controller + '/query?'
        + 'OperatorId=' + this.$store.state.operator.mid,
        {
          "merchant.mid":this.$store.state.operator.mid,
          "page": val.page,
          "pageSize": val.pageSize,
          "sortType": val.sortType,
          "sortBy": val.sortBy,
          "startTime": (this.$helper.renderTime(val.startTime1).split(' ')[0] + ' ' + this.$helper.renderTime(val.startTime2).split(' ')[1]),
          "endTime": (this.$helper.renderTime(val.endTime1).split(' ')[0] + ' ' + this.$helper.renderTime(val.endTime2).split(' ')[1])
        })
        .then(res => {
          for (let i = 0; i < res.data.length; ++i) {
            this.dataPreprocessing(res.data[i]);
          }
          _this.$store.state.List.GoodsVo = res.data;
          _this.LoadInfo(res.data);
          //console.log(_this.user);
        })
    },
    /**
     * @查询封装函数
     * */
    queryHaveNameHaveState(val) {
      let _this = this;
      this.axios.post(this.$store.state.baseURL + 'client/' + this.controller + '/query?'
        + 'OperatorId=' + this.$store.state.operator.mid,
        {
          "merchant.mid":this.$store.state.operator.mid,
          "name": val.name,
          "merchant.name": val.name,
          "merchant.describe.content": val.name,
          "card.name": val.name,
          "describe.content": val.name,
          "activity.name": val.name,
          "page": val.page,
          "pageSize": val.pageSize,
          "sortType": val.sortType,
          "sortBy": val.sortBy,
          "state": val.state,
          "startTime": (this.$helper.renderTime(val.startTime1).split(' ')[0] + ' ' + this.$helper.renderTime(val.startTime2).split(' ')[1]),
          "endTime": (this.$helper.renderTime(val.endTime1).split(' ')[0] + ' ' + this.$helper.renderTime(val.endTime2).split(' ')[1])
        })
        .then(res => {
          for (let i = 0; i < res.data.length; ++i) {
            this.dataPreprocessing(res.data[i]);
          }
          _this.$store.state.List.GoodsVo = res.data;
          _this.LoadInfo(res.data);
          //console.log(_this.user);
        })
    },
    /**
     * @查询封装函数
     * */
    queryHaveNameNoState(val) {
      let _this = this;
      this.axios.post(this.$store.state.baseURL + 'client/' + this.controller + '/query?'
        + 'OperatorId=' + this.$store.state.operator.mid,
        {
          "name": val.name,
          "merchant.mid":this.$store.state.operator.mid,
          "merchant.name": val.name,
          "merchant.describe.content": val.name,
          "card.name": val.name,
          "describe.content": val.name,
          "activity.name": val.name,
          "page": val.page,
          "pageSize": val.pageSize,
          "sortType": val.sortType,
          "sortBy": val.sortBy,
          "startTime": (this.$helper.renderTime(val.startTime1).split(' ')[0] + ' ' + this.$helper.renderTime(val.startTime2).split(' ')[1]),
          "endTime": (this.$helper.renderTime(val.endTime1).split(' ')[0] + ' ' + this.$helper.renderTime(val.endTime2).split(' ')[1])
        })
        .then(res => {
          for (let i = 0; i < res.data.length; ++i) {
            this.dataPreprocessing(res.data[i]);
          }
          _this.$store.state.List.GoodsVo = res.data;
          _this.LoadInfo(res.data);
          //console.log(_this.user);
        })
    },
    /**
     * @套餐嵌入内容
     * */
    packageOn(val) {
      this.packageDialogVisible = true;
      this.packageList = val;
    },
    /**
     * @嵌入内容
     * */
    Content(val) {
      this.centerDialogVisible = true;
      this.content = val;
    },
    /**
     * @对数据时间预处理
     * */
    dataPreprocessing(res) {
      const _this = this;
      //console.log(res);
      res.creattime = _this.$helper.renderTime(res.creattime);
      res.merchant.creattime = _this.$helper.renderTime(res.merchant.creattime);
      res.merchant.describe.creattime = _this.$helper.renderTime(res.merchant.describe.creattime);
      res.merchant.describe.updatetime = _this.$helper.renderTime(res.merchant.describe.updatetime);
      res.merchant.pic.creattime = _this.$helper.renderTime(res.merchant.pic.creattime);
      res.card.creattime = _this.$helper.renderTime(res.card.creattime);
      res.picture.creattime = _this.$helper.renderTime(res.picture.creattime);
      //res.picture.creattime = _this.$helper.renderTime(res.picture.creattime);
      res.describe.creattime = _this.$helper.renderTime(res.describe.creattime);
      res.describe.updatetime = _this.$helper.renderTime(res.describe.updatetime);
      res.activity.creattime = _this.$helper.renderTime(res.activity.creattime);
      res.activity.failtime = _this.$helper.renderTime(res.activity.failtime);
      res.activity.rule.creattime = _this.$helper.renderTime(res.activity.rule.creattime);
      for (let j = 0; j < res.list.length; ++j) {
        res.list[j].creattime = _this.$helper.renderTime(res.list[j].creattime);
      }
    },
    /**
     * @对数据时间预处理T
     * */
    dataPreprocessingT(res) {
      const _this = this;
      //console.log(res);
      let str = 'yyyy-MM-dd' + 'T' + 'hh:mm:ss.SSS';
      res.creattime = _this.$helper.getTtime(res.creattime, str);
      res.merchant.creattime = _this.$helper.getTtime(res.merchant.creattime, str);
      res.merchant.describe.creattime = _this.$helper.getTtime(res.merchant.describe.creattime, str);
      res.merchant.describe.updatetime = _this.$helper.getTtime(res.merchant.describe.updatetime, str);
      res.merchant.pic.creattime = _this.$helper.getTtime(res.merchant.pic.creattime,str);
      res.card.creattime = _this.$helper.getTtime(res.card.creattime, str);
      res.picture.creattime = _this.$helper.getTtime(res.picture.creattime, str);
      //res.picture.creattime = _this.$helper.getTtime(res.picture.creattime, str);
      res.describe.creattime = _this.$helper.getTtime(res.describe.creattime, str);
      res.describe.updatetime = _this.$helper.getTtime(res.describe.updatetime, str);
      res.activity.creattime = _this.$helper.getTtime(res.activity.creattime, str);
      res.activity.failtime = _this.$helper.getTtime(res.activity.failtime, str);
      res.activity.rule.creattime = _this.$helper.getTtime(res.activity.rule.creattime, str);
      for (let j = 0; j < res.list.length; ++j) {
        res.list[j].creattime = _this.$helper.getTtime(res.list[j].creattime, str);
      }
    },
    /**
     * @添加
     * */
    insert() {
      this.pojo.gid="";
      this.pojo.name = "";
      this.pojo.merchant.mid = this.$store.state.operator.mid;
      this.pojo.card.caid = "";
      this.pojo.picture.picid = "1";
      this.pojo.describe.iid = "1";
      this.pojo.number = "";
      this.pojo.price="";
      this.pojo.activity.aid = "";
      this.pojo.view = "";
      this.pojo.sale = "";
      this.pojo.creattime = "";
      this.pojo.state = 2;
      this.dialogFormVisible = true;
      let temp =[];
      for (let i = 0; i < this.pojo.list.length; i++) {
          this.pojo.list[i].gid = "";
          this.pojo.list[i].sgid = "";
          this.pojo.list[i].creattime = "";
          this.pojo.list[i].state = 1;
          this.pojo.list[i].price = "";
          this.pojo.list[i].number = "";
          this.pojo.list[i].unit = "";
          temp.push(this.pojo.list[0]);
          break;
      }
      this.pojo.list=temp;
    },
    /**
     * @修改
     * */
    change(val) {
      //console.log(val)
      this.pojo = this.$helper.clone(val);
      this.dialogFormVisible = true;
    },
    /**
     * @保存
     */
    save(val) {
      let _this = this;
      //this.dataPreprocessingT(val)
      //console.log(val)
      this.axios.post(this.$store.state.baseURL + 'client/' + this.controller + '/save?' + 'OperatorId=' + this.$store.state.operator.mid,
        {
          "gid": val.gid,
          "name": val.name,
          "price":val.price,
          "merchant": val.merchant,
          "card": val.card,
          "picture": val.picture,
          "describe": val.describe,
          "number": val.number,
          "activity": val.activity,
          "creattime": "",
          "state": val.state,
          "view": val.view,
          "sale": val.sale,
          "list": val.list
        })
        .then(res => {
          //console.log(res.data)
          _this.search(_this.queryLike);
        })
      this.dialogFormVisible = false;
    },
    /**
     * @物理删除
     */
    phydele(val, index, id) {
      let _this = this;
      //this.dataPreprocessingT(val);
      this.axios.post(this.$store.state.baseURL + 'client/' + this.controller + '/delete?' + 'OperatorId=' + this.$store.state.operator.mid + '&index=' + index + '&id=' + id, {
        "gid": val.gid,
        "name": val.name,
        "price":val.price,
        "merchant": val.merchant,
        "card": val.card,
        "picture": val.picture,
        "describe": val.describe,
        "number": val.number,
        "activity": val.activity,
        "creattime": val.creattime,
        "state": val.state,
        "view": val.view,
        "sale": val.sale,
        "list": val.list
      })
        .then(res => {
          _this.search(_this.queryLike);
        })
    },
    /**
     * @物理删除套餐
     */
    phydele2(pojo,val, index, id) {
      let _this = this;
      //console.log(pojo);
      this.deleteSalegoods2(pojo,val.list);
      //console.log(val.list);
      //this.dataPreprocessingT(val);
      this.axios.post(this.$store.state.baseURL + 'client/' + this.controller + '/delete?' + 'OperatorId=' + this.$store.state.operator.mid + '&index=' + index + '&id=' + id, {
        "gid": val.gid,
        "name": val.name,
        "price":val.price,
        "merchant": val.merchant,
        "card": val.card,
        "picture": val.picture,
        "describe": val.describe,
        "number": val.number,
        "activity": val.activity,
        "creattime": val.creattime,
        "state": val.state,
        "view": val.view,
        "sale": val.sale,
        "list": val.list
      })
        .then(res => {
          _this.search(_this.queryLike);
        })
    },
    /**
     * @封禁-启用
     */
    enable(pojo, index, id, type) {
      let _this = this;
      let val = this.$helper.clone(pojo);
      //this.dataPreprocessingT(val);
      this.axios.put(this.$store.state.baseURL + 'client/' + this.controller + '/enable?' + 'OperatorId=' + this.$store.state.operator.mid + '&index=' + index + '&id=' + id + '&type=' + type, {
        "gid": val.gid,
        "name": val.name,
        "price":val.price,
        "merchant": val.merchant,
        "card": val.card,
        "picture": val.picture,
        "describe": val.describe,
        "number": val.number,
        "activity": val.activity,
        "creattime": val.creattime,
        "state": type,
        "view": val.view,
        "sale": val.sale,
        "list": val.list
      })
        .then(res => {
          _this.search(_this.queryLike);
        })
    },
    /**
     * @封禁-启用套餐
     */
    enable2(val2, pojo, index, id, type) {
      //console.log(val);
      val2.state = type;
      let _this = this;
      let val = this.$helper.clone(pojo);
      //this.dataPreprocessingT(val);
      this.axios.put(this.$store.state.baseURL + 'client/' + this.controller + '/enable?' + 'OperatorId=' + this.$store.state.operator.mid + '&index=' + index + '&id=' + id + '&type=' + type, {
        "gid": val.gid,
        "name": val.name,
        "price":val.price,
        "merchant": val.merchant,
        "card": val.card,
        "picture": val.picture,
        "describe": val.describe,
        "number": val.number,
        "activity": val.activity,
        "creattime": val.creattime,
        "state": val.state,
        "view": val.view,
        "sale": val.sale,
        "list": val.list
      })
        .then(res => {
          _this.search(_this.queryLike);
        })
    },
    /**
     * @查询
     * */
    search(val) {
      //console.log(val);
      if (val.name === "") {
        if (val.state === "") {
          this.queryNoNameNoState(val);
        } else {
          this.queryNoNameHaveState(val);
        }
      } else {
        if (val.state === "") {
          this.queryHaveNameNoState(val);
        } else {
          this.queryHaveNameHaveState(val);
        }
      }
    }
    ,
    /**
     *
     * @导入具体列表的数据
     */
    LoadMsg() {
      let _this = this;
      this.axios.post(this.$store.state.baseURL + 'client/' + this.controller + '/query?' + 'OperatorId=' + this.$store.state.operator.mid,
        {
          "page": 1,
          "pageSize": 10,
          "sortType": 0,
          "sortBy": 10,
          "merchant.mid":this.$store.state.operator.mid,
        })
        .then(res => {
          for (let i = 0; i < res.data.length; ++i) {
            this.dataPreprocessing(res.data[i]);
          }
          _this.$store.state.List.GoodsVo = res.data;
          _this.LoadInfo(res.data);
          //console.log(res.data);
        })
    }
    ,
    /**
     *
     * @更新当前页面的数据(data<->this.$store.state)
     */
    LoadInfo(val) {
      this.user = val;
    }
    ,
  },
}
</script>

<style scoped>
.product-buyer-name {
  max-width: 180px;
  max-height: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
</style>
